from flask import Blueprint,request,make_response,redirect,jsonify
from application.models.users.user import *
from utils.captcha.captcha import captcha
from utils.myredis import r
import redis
from utils.myjwt import myjwt
from qiniu import Auth

cc_blue = Blueprint("ccbule",__name__)


@cc_blue.route("/gettags")
def gettags():
    tags=Tags.query.all()
    tagslist=[{"id":i.id,"name":i.name} for i in tags]
    types=Ctype.query.all()
    typelist=[{"id":i.id,"name":i.name} for i in types]
    ctype=CourseType.query.all()
    clist=[{"id":i.id,"name":i.name} for i in ctype]
    return jsonify({"code":200,"tags":tagslist,"types":typelist,"clist":clist})


@cc_blue.route("/qniu")
def qniu():
    access_key = 'kc099mMq_-M0SRLSjgRpYIlg6jl5x60m3yfTkAkb'
    secret_key = '_9HvQl9D4dl_FGywW9fIwAN0d1ujH92SOrSbc5dm'
    q = Auth(access_key, secret_key)
    #要上传的空间
    bucket_name = 'h2203ab'
    #上传后保存的文件名
    #生成上传 Token，可以指定过期时间等
    token = q.upload_token(bucket_name)
    return  jsonify({'code':200,'qtoken':token})